#include "If.h"
#include "IVisitor.h"

If::If(const exprTypePtr& test, const StmtTypeList& body, const suiteTypePtr& orelse, int nodeId):
    stmtType(nodeId),
    _test(test),
    _body(body),
    _orelse(orelse)
{
}
    
If::~If()
{
    _body.clear();
}
    
Ast::AstTypes If::type() const
{
    return Ast::If;
}
    

exprTypePtr If::test()
{
    return _test;
}

void If::setTest(const exprTypePtr& test)
{
    _test = test;
}

StmtTypeList If::body()
{
    return _body;
}

void If::setBody(const StmtTypeList& body)
{
    _body = body;
}

suiteTypePtr If::orelse()
{
    return _orelse;
}

void If::setOrelse(const suiteTypePtr& orelse)
{
    _orelse = orelse;
}

    
QString If::toString() const
{
    return QString("If[test=%1, body=%2, orelse=%3]").
                arg(_test ? _test->toString():"").
                arg(_body.toString()).
                arg(_orelse ? _orelse->toString():"");
}
    
void If::accept(IVisitor* visitor, const SimpleNodePtr& node)
{
    visitor->visitIf(node.dynamicCast<If>());
}
    
void If::traverse(IVisitor* visitor)
{
    if (_test != NULL)
        _test->accept(visitor, _test);
    _body.traverse(visitor);
    if (_orelse != NULL)
        _orelse->accept(visitor, _orelse);
}